package com.yq.day18._07arraylist;

import java.util.ArrayList;

/**
 * @author 3307235355@qq.com
 * @since 2022/06/19 22:08
 */
public class Demo03 {
    public static void main(String[] args) {
    //    找到小于18 岁的学生信息
        ArrayList<Student> stu = new ArrayList<>();
        Student s1 = new Student("张三 ",12);
        Student s2 = new Student("李四 ",22);
        Student s3 = new Student("王五 ",2);
        stu.add(s1);
        stu.add(s2);
        stu.add(s3);
        ArrayList<Student> newList = getNewList(stu);
        for (int i = 0; i < newList.size(); i++) {
            Student student = newList.get(i);
            System.out.println(student);
            System.out.println(student.getAge()+"   "+student.getName());

        }
    }
    public static ArrayList<Student> getNewList(ArrayList<Student> stu){
        ArrayList<Student> newStu = new ArrayList<>();
        for (int i = 0; i < stu.size(); i++) {
            Student stu1 = stu.get(i);
            if (stu1.getAge()<=18){
                newStu.add(stu1);
            }
        }
        return newStu;
    }
}
